﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class TJAnimSetup : MonoBehaviour {
    public TJItem[] items;

    void Start() {
        if (items != null || items.Length > 0) {
            for (int i = 0; i < items.Length; i++) {
                items[i].Init(this);
            }
        }
    }

    [Serializable]
    public class TJItem {
        public GameObject root;
        public float showDuration, hideDuration;
        public bool initIsShow;

        public void Init(MonoBehaviour mono) {
            this.mono = mono;
            mono.StartCoroutine(Iiii(initIsShow));
        }

        MonoBehaviour mono;

        public IEnumerator Iiii(bool isShow) {
            root.gameObject.SetActive(isShow);
            if (isShow) {
                yield return new WaitForSeconds(showDuration);
                mono.StartCoroutine(Iiii(!isShow));
            } else {
                yield return new WaitForSeconds(hideDuration);
                mono.StartCoroutine(Iiii(!isShow));
            }
        }
    }
}
